#include <stddef.h>
#include <stdbool.h>
#include <stdlib.h>
 struct TreeNode {
    int val;
    struct TreeNode *left;
    struct TreeNode *right;
  };


int TreeMaxDepth(struct TreeNode* root)
{
    if(root==NULL) return 0;
    int left=TreeMaxDepth(root->left);
    int right=TreeMaxDepth(root->right);
    return left>right ? left+1:right+1;
}
bool isBalanced(struct TreeNode* root){
    if(root==NULL) return true;
    int left=TreeMaxDepth(root->left);
    int right=TreeMaxDepth(root->right);
    if(abs(left-right)>1)
    { 
        return false;//如果大于1了那就不是平衡二叉树 直接返回false
    }
    else return isBalanced(root->left)&&isBalanced(root->right); //判断左右子树的深度差
}